package edu.bu.met683.TravelDroid.data;

import org.xmlpull.v1.XmlPullParser;

import com.google.android.maps.GeoPoint;

/**
 * This class is the java object representation of a Point Of Interest that
 * traveldroid provides to the user.
 */
public class PointOfInterest {

	public static final String NO_AUDIO_FILE_STRING = "NoAudioFile";

	private String name;
	private String description;
	private GeoPoint point;
	private String audioFileName = NO_AUDIO_FILE_STRING;
	private String wikiUrl;

	/**
	 * Constructor that creates a point of interest using the data provided for
	 * each field.
	 * 
	 * @param n
	 * @param d
	 * @param geoString
	 */
	public PointOfInterest(String n, String d, String geoString) {
		name = n;
		description = d;

		point = DataUtilities.convertStringToGeoPoint(geoString);
	}

	/**
	 * Constructor that uses an XML Parser to generate a PointOfInterest object.
	 * 
	 * @param parser
	 */
	public PointOfInterest(XmlPullParser parser) {
		try {
			String tag = parser.getName();

			while (!tag.equals("Placemark")) {

				if ((tag != null) && tag.equals("name")) {
					parser.next();
					name = parser.getText();
					parser.next();
				} else if ((tag != null) && tag.equals("description")) {
					parser.next();
					description = parser.getText();
					parser.next();
				} else if ((tag != null) && tag.equals("audiofile")) {
					parser.next();
					audioFileName = parser.getText();
					parser.next();
				} else if ((tag != null) && tag.equals("wikiurl")) {
					parser.next();
					wikiUrl = parser.getText();
					parser.next();
				} else if ((tag != null) && tag.equals("Point")) {
					parser.next();
					tag = parser.getName();

					if ((tag != null) && tag.equals("coordinates")) {
						parser.next();
						String coordString = parser.getText();
						point = DataUtilities
								.convertStringToGeoPoint(coordString);
						parser.next();
					}
					parser.next();
				}
				parser.next();
				tag = parser.getName();
			}
			parser.next();
		} catch (Exception e) {

		}
	}

	/**
	 * Gets the name of the POI
	 * 
	 * @return
	 */
	public String getName() {
		return name;
	}

	/**
	 * Gets a description of the POI
	 * 
	 * @return
	 */
	public String getDescription() {
		return description;
	}

	/**
	 * Gets the location of the POI.
	 * 
	 * @return a GeoPoint object representing the location of the POI.
	 */
	public GeoPoint getPoint() {
		return point;
	}

	/**
	 * 
	 * 
	 * @return
	 */
	public String getAudioFileName() {
		return audioFileName;
	}

	/**
	 * 
	 * 
	 * @return
	 */
	public String getWikiUrl() {
		return wikiUrl;
	}
}
